package tree;

public class FanZhuanTree {
    //二叉树节点类
    static class Node{
        int value;
        Node left;
        Node right;
        public Node(int value) {
            this.value = value;
        }
    }

    public static void main(String[] args) {
        Node root = new Node(1);
        root.left = new Node(2);
        root.right = new Node(3);
        root.left.left = new Node(4);
        root.left.right = new Node(5);
        root.right.left = new Node(6);
        root.right.right = new Node(7);

        fanZhuan(root);
        print(root);
    }

    private static void print(Node root) {
        if(root == null) return;
        System.out.println(root.value);
        print(root.left);
        print(root.right);
    }

    private static void fanZhuan(Node root) {
        if(root == null) return ;
        fanZhuan(root.left);
        fanZhuan(root.right);
        Node temp = root.left;
        root.left = root.right;
        root.right = temp;
    }
}